package com.marvels.approve.process.api.hystrix;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.marvels.approve.process.api.MarvelDecisionApi;
import com.marvels.approve.process.dto.DecisionMsgDTO;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.coreservice.service.MarvelDecisionService;

import cn.hutool.core.bean.BeanUtil;

@Service
public class MarvelDecisionApiHystrix implements MarvelDecisionApi {

	@Autowired
	private MarvelDecisionService marvelDecisionService;
	
	@Override
	public MarvelsResultDTO trailApproveAmount(DecisionMsgDTO decisionMsgDTO) {
		try {
			com.marvels.dubbo.coreservice.dto.DecisionMsgDTO param = new com.marvels.dubbo.coreservice.dto.DecisionMsgDTO();
			BeanUtil.copyProperties(decisionMsgDTO, param);
			com.marvels.dubbo.coreservice.dto.DecisionMsgDTO apiResult = marvelDecisionService.trailApprovedAmount(param);
			MarvelsLogUtil.getInstance().info("MarvelDecisionApi.trailApproveAmount direct call success!");
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),apiResult);
		}catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("调用决策试算审批核定金额异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}
	}

	@Override
	public MarvelsResultDTO YYDTrailApproveAmount(DecisionMsgDTO decisionMsgDTO) {
		try {
			com.marvels.dubbo.coreservice.dto.DecisionMsgDTO param = new com.marvels.dubbo.coreservice.dto.DecisionMsgDTO();
			BeanUtil.copyProperties(decisionMsgDTO, param);
			com.marvels.dubbo.coreservice.dto.DecisionMsgDTO apiResult = marvelDecisionService.search51gjj(param);
			MarvelsLogUtil.getInstance().info("MarvelDecisionApi.YYDTrailApproveAmount direct call success!");
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), apiResult);
		}catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("调用决策试算审批核定金额异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}
	}

	@Override
	public MarvelsResultDTO YFDTrailApproveAmount(DecisionMsgDTO decisionMsgDTO) {
		try {
			com.marvels.dubbo.coreservice.dto.DecisionMsgDTO param = new com.marvels.dubbo.coreservice.dto.DecisionMsgDTO();
			BeanUtil.copyProperties(decisionMsgDTO, param);
			com.marvels.dubbo.coreservice.dto.DecisionMsgDTO apiResult = marvelDecisionService.getShangHaiAmount(param);
			MarvelsLogUtil.getInstance().info("MarvelDecisionApi.YFDTrailApproveAmount direct call success!");
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), apiResult);
		}catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("调用决策试算审批核定金额异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}
	}

}
